package com.example.composeplayground.screens.main

import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import com.example.composeplayground.common.RequestUtils
import com.example.composeplayground.models.UserInfo
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

@Preview
@Composable
fun LocationScreen() {
    Column {
        Text(text = "LocationScreen")
        Button(onClick = {
            CoroutineScope(Dispatchers.Main).launch {
                val resp =
                    RequestUtils.get<UserInfo>("http://192.168.0.102:5246/Account/Test")
                println(resp.data.name + ", " + resp.data.avatar)
            }
        }) {
            Text(text = "发起网络请求")
        }
        Button(onClick = {
            CoroutineScope(Dispatchers.Main).launch {
                val resp =
                    RequestUtils.get<UserInfo>("http://192.168.0.102:5246/Account/Test1")
                println(resp.message)
            }
        }) {
            Text(text = "发起网络请求1")
        }
        Button(onClick = {
            CoroutineScope(Dispatchers.Main).launch {
                val resp =
                    RequestUtils.get<UserInfo>("http://192.168.0.102:5246/Account/Test2")
                println(resp.message)
            }
        }) {
            Text(text = "发起网络请求2")
        }
    }
}